package spring.cloud.tasks.tasks_manager.tasks_manager.service;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadFactory;

/**
 * zk treecache的线程Factory
 */
@Slf4j
@Setter
@Getter
public class TreeCacheThreadFactory implements ThreadFactory {

    private String threadName;

    public TreeCacheThreadFactory(String threadName) {
        this.threadName = "treecache-for-" + threadName;
    }

    @Override
    public Thread newThread(Runnable runnable) {
        Thread thread = new Thread(runnable, threadName);
        thread.setDaemon(false);
        thread.setPriority(Thread.NORM_PRIORITY);
        return thread;
    }
}
